//
//  SLTrace.m
//  SLAdingo
//
//  Created by 徐 廷 on 10/04/30.
//  Copyright 2010 adingo Inc. All rights reserved.
//

#import "SLTrace.h"

static BOOL __SLLogOn=NO;

@implementation SLTrace

+ (void) initialize
{
	char * env=getenv("SLLogOn");
	if(strcmp(env==NULL?"":env,"NO")!=0)
		__SLLogOn=YES;
}

+ (void) logFile:(char*)sourceFile lineNumber:(int)lineNumber format:(NSString*)format, ...;
{
	if(__SLLogOn==NO)
		return;

	va_list ap;
	NSString *print,*file;
    
	va_start(ap,format);
	file=[[NSString alloc] initWithBytes:sourceFile 
                                  length:strlen(sourceFile) 
                                encoding:NSUTF8StringEncoding];
	print=[[NSString alloc] initWithFormat:format arguments:ap];
	va_end(ap);
    //NSLog handles synchronization issues
	NSLog(@"%s:%d %@",[[file lastPathComponent] UTF8String],
          lineNumber,print);
	[print release];
	[file release];
	
	return;
}

+(void)setLogOn:(BOOL)logOn
{
	__SLLogOn=logOn;
}


@end
